package com.sk.cardeal.act.home.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.dyhdyh.widget.loading.dialog.LoadingDialog;
import com.sk.cardeal.R;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.callback.HandleDataCallBack;
import com.sk.cardeal.entity.ApplyOrderDetails;
import com.sk.cardeal.utils.AppApi;
import com.sk.cardeal.utils.MyUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sk on 2017/12/22.
 */

public class ApplyMachineDetailsAct extends BaseActivity implements HandleDataCallBack {
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_code)
    TextView tvCode;
    @BindView(R.id.tv_pep)
    TextView tvPep;
    @BindView(R.id.parts_ll)
    LinearLayout partsLl;
    private String id;
    private LoadingDialog loadingDialog;

    @Override
    protected int getContentView() {
        return R.layout.activity_apply_machine_details;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        loadingDialog = MyUtils.getLoadingDialog(mContext, false);
        loadingDialog.show();
        id = getIntent().getStringExtra("id");
        AppApi.getApplyDetails(id, this, 0, this);

    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void handlerSuccessData(String result, int tag) {
        loadingDialog.cancelDialog();
        ApplyOrderDetails applyOrderDetails = JSON.parseObject(result, ApplyOrderDetails.class);
        tvCode.setText("申领单号：" + applyOrderDetails.getReturnObject().getCode());
        tvPep.setText("申领人：" + applyOrderDetails.getReturnObject().getPersonName());
        List<ApplyOrderDetails.ReturnObjectBean.DetailListBean> detailListBeanList = applyOrderDetails.getReturnObject().getDetailList();
        for (ApplyOrderDetails.ReturnObjectBean.DetailListBean detailListBean : detailListBeanList) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.item_apply_use, partsLl, false);
            TextView tv_name = view.findViewById(R.id.tv_name);
            tv_name.setText(detailListBean.getName());
            TextView tv_vin = view.findViewById(R.id.tv_vin);
            tv_vin.setText(detailListBean.getVin());
            TextView tv_num = view.findViewById(R.id.tv_num);
            tv_num.setText(detailListBean.getCount()+"");
            partsLl.addView(view);
        }
    }

    @Override
    public void handlerFailData(String failString, int tag) {
        loadingDialog.cancelDialog();
    }

    @Override
    public void handleErrorData(String error, int tag) {
        loadingDialog.cancelDialog();
    }
}
